<?php
/*
	排队
*/

defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_RQ['op']=='list'){
	//顾客管理
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['mobile'])){
		$params['mobile']=$_RQ['mobile'];
		$return['params']['mobile']=$_RQ['mobile'];
	}
	if(!empty($_RQ['name'])){
		$params['name like']='%'.$_RQ['name'].'%';
		$return['params']['name']=$_RQ['name'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 20;
	$total='';
	$fields=array();
	$list=pdo_getslice('jy_meye_member',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		$fields=array('avatar','nickname','username','mobile','credit1','credit2','createtime','fromuser','from_os');
		foreach($list as &$item){			
			$members=pdo_get('core_members',array('id'=>$item['mid']),$fields);
			if($members['from_os']==1 && $members['wxgid'] && !$members['wxapptitle']){
				$members['wxapptitle']='小程序已删除';
			}
			$item['from_os']=get_ostitle()[$members['from_os']];
			$item=array_merge($members,$item);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'顾客列表'),
		),
		'list'=>array('data'=>'list','key'=>'mid','edit'=>false,'list'=>array(
			array('name'=>'id','title'=>'ID','type'=>'string'),
			array('title'=>'账号_username','type'=>'img_string','img'=>'avatar',
			'data'=>array(
				array('title'=>'账号：','name'=>'username'),
				array('title'=>'昵称：','name'=>'nickname','unit'=>'from_os')
				)
			),
			array('name'=>'name','title'=>'顾客名称','type'=>'string'),
			array('name'=>'mobile','title'=>'顾客手机','type'=>'string'),
			array('name'=>'wxapptitle','title'=>'对应小程序','type'=>'string'),
			array('name'=>'mobile','title'=>'手机_mobile','type'=>'string'),
			array('name'=>'fromuser','title'=>'推荐人id_fromuser ID','type'=>'string'),
			array('name'=>'credit1','title'=>'积分','type'=>'string'),
			array('name'=>'credit2','title'=>'余额','type'=>'string'),
			array('name'=>'createtime','title'=>'注册日期','type'=>'time'),
			array('name'=>'creditlog','title'=>'积分/余额日志','type'=>'href'),
			array('name'=>'isblack','title'=>'是否拉黑','type'=>'switch','set'=>'isblack'),
		),'action'=>array(
			array('type'=>'href','action'=>'core/member.member/recharge/','title'=>'充值'),
			array('type'=>'href','action'=>'core/member.member/cpassword/','title'=>'重置密码'),
		)),
		'search'=>array(
			array('type'=>'string','width'=>'15','title'=>'会员ID','name'=>'id','help'=>''),
			array('type'=>'string','width'=>'15','title'=>'顾客名称','name'=>'mobile','help'=>''),
			array('type'=>'string','width'=>'15','title'=>'顾客手机','name'=>'name','help'=>''),
		),
	);
	$return['htmls']=$htmls;
	$return['isblacks']=array(
		'0'=>'正常',
		'1'=>'拉黑',
	);
	
	exi($return);
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['mid']){
		$del[]=$_RQ['mid'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_meye_member',array('mid'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}
if($_RQ['op']=='isblack'){
	$id=intval($_RQ['mid']);
	if(!$id){
		exi('参数错误！','error');
	}
	$update=array();
	$post=get_postdata();
	if(isset($post['isblack'])){
		$update['isblack']=intval($post['isblack']);
	}
	if($update){
		pdo_update('jy_meye_member',$update,array('mid'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	exi('操作成功！');
}